<head>
<script type="text/javascript">
function validateipaddr(ipaddr) {
   ipaddr = ipaddr.replace( /\s/g, ""); //remove spaces for checking
   var re = /^(\d{1,3}|\*)\.(\d{1,3}|\*)\.(\d{1,3}|\*)\.(\d{1,3}|\*)$/;
   if (re.test(ipaddr)) {
       //split into units with dots "."
       var p = ipaddr.split(".");
       if (parseInt(parseFloat(p[0])) == 0 || parseInt(parseFloat(p[3])) == 0) {
           return false;
       }
       for (var i=0; i<p.length; i++) {
           if (parseInt(parseFloat(p[i])) > 255 && (p[i] != '*')){
               return false;
           }
       }
       return true;
   } else {
       return false;
   }
}

function checkIPField(){
	var ipaddr=document.getElementById("ipText").value;
	if(validateipaddr(ipaddr)){
		document.getElementById("ipButton").disabled=false;
	}else{document.getElementById("ipButton").disabled=true;}
}
</script>

</head>
<body>
<div id="container">
<?php $this->message ?>
<br/>
<form method="post" action="/index/searchbyip">
	<input type="hidden" name="searchType" value="ipAddress"/>
	<table>
	<tr><b>Search by IP Address (e.g. #.#.#.#):</b></tr>
	<tr><td><input id="ipText" type="text" name="ip_address" onkeyup="checkIPField()"/></td><td><input id="ipButton"type="submit" name="searchByIP" value="Search by IP"/></td></tr>
	</table>
</form>
<br/>
<form method="post" action="/index/searchbybuilding">
	<input type="hidden" name="searchType" value="building"/>
	<table>
	<tr><b>Search by Building:</b></tr>
	<tr><td><select name="building">
	<?php
		foreach($this->buildings as $building){
			echo("<option name='".$building."' value='".$building."'>".$building."</option>");
		}
	?>
	</select></td><td><input type="submit" name="searchByBuilding" value="Search by Building"/></td></tr>
	</table>
</form>
<br/>
<form method="post" action="/index/searchbyfield">
	<input type="hidden" name="searchType" value="field"/>
	<table>
	<tr><b>Search by Field:</b></tr>
	<tr><select name="field">
		<option name="text1" disabled="true" value="test">Select Field</option>
		<option name="text2" disabled="true" value="test">---------------------</option>
		<option name="Model" value="Model">Model</option>
		<option name="Serial Number" value="Serial Number">Serial Number</option>
		<option name="Comments" value="Comments">Comments</option>
	</select></tr>
	<tr><td><input type="text" name="criteria"/></td><td><input type="submit" name="searchByField" value="Search by Field"/></td></tr>
	</table>
</form>
<script type="text/javascript">
document.getElementById("ipButton").disabled=true;
</script>
</div>
</body>
